/******************************************************************************
 * (C) Copyright 2013 Atech-Automotive
 * FILE NAME:    uds_diag_interface.h
 * DESCRIPTION:
 * 
 * DATE BEGUN:   2015/05/07
 * BY:           hui.pang
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */

#ifndef _UDS_DIAG_INTERFACE_H_
#define _UDS_DIAG_INTERFACE_H_

#pragma CODE_SEG  OTHER_ROM


/*****************************************************************************
**  typedef
*****************************************************************************/
/*
** Data byte offsets in message
*/
typedef enum
{
    __MODE   = 0,
    _DATA1  = 1,
    _DATA2  = 2,
    _DATA3  = 3,
    _DATA4  = 4,
    _DATA5  = 5,
    _DATA6  = 6,
    _DATA7  = 7,

} Uds_DataByteOffset_E;

/* g_uds_diag_status bit mapped status bits */ 
typedef enum
{
    COMMANDRCVD          = 0x80, /*Set when message received is identified by diag layer */
    NEGRESP78_PROCESSING = 0x40, /*Set when Resp78 handling is going on */
    NEGRESP78_WAIT_60SEC = 0x20, /*Set when Resp78 handling is going on,clear after 60 secs */
    PROCESSING_MSG       = 0x01, /*Set when processing diagnostic message */
    KEEPING_DIAG         = 0x02,
    
} Uds_DiagSts_E;

/*  Diag mode bytes  */
typedef enum
{
    ENTRDIAG        = 0x10,   /* Enter diagnostics*/
    ECURESET        = 0x11,   /* ECU reset */
    TSTRPRNT        = 0x3E,   /* Tester present   */
    SECACCESS       = 0x27,   /* Security Access  */
    RDBYID          = 0x22,   /* Read data by ID  */
    WRBYID          = 0x2E,   /* Write Data By ID */
    DTCINFO         = 0x19,   /* Read DTC info    */
    CLRDTCRQ        = 0x14,   /* Clear DTC info   */
    ROUTINECTRL     = 0x31,   /* routine control  */
    IOCTRLBYID      = 0x2F,   /* InputOutput Control by Identifier */
    COMMCTRL        = 0x28,   /* Comm Ctrl */
    DTCSETTINGCTRL  = 0x85,   /* DTC Setting Ctrl */
    RDMBYADDR       = 0x23,   /* Read Memory By Address */
    WRMBYADDR       = 0x3D,   /* Write Memory By Address */

} Uds_DiagMode_E;



/*****************************************************************************
**#include 
*****************************************************************************/


/*****************************************************************************
** Constant Macro Definition
*****************************************************************************/


/*****************************************************************************
** System Macro Definition
*****************************************************************************/
#define DiagExServiceNotSupported_Nrc11()                     /* 0x11 */ UdsInterface_SendNegativeResponse(((UINT8)0x11)) 
#define DiagExSubFunctionNotSupportedOrInvalidFormat_Nrc12()  /* 0x12 */ UdsInterface_SendNegativeResponse(((UINT8)0x12)) 
#define DiagExIncorrectMessagelengthOrInvalidFormat_Nrc13()   /* 0x13 */ UdsInterface_SendNegativeResponse(((UINT8)0x13)) 
#define DiagExResponseTooLong_Nrc14()                         /* 0x14 */ UdsInterface_SendNegativeResponse(((UINT8)0x14)) 
#define DiagExBusyRepeatRequest_Nrc21()                       /* 0x21 */ UdsInterface_SendNegativeResponse(((UINT8)0x21)) 
#define DiagExConditionsNotCorrect_Nrc22()                    /* 0x22 */ UdsInterface_SendNegativeResponse(((UINT8)0x22)) 
#define DiagExRequestSequenceError_Nrc24()                    /* 0x24 */ UdsInterface_SendNegativeResponse(((UINT8)0x24)) 
#define DiagExRequestOutofRange_Nrc31()                       /* 0x31 */ UdsInterface_SendNegativeResponse(((UINT8)0x31)) 
#define DiagExsecurityAccessDenied_Nrc33()                    /* 0x33 */ UdsInterface_SendNegativeResponse(((UINT8)0x33)) 
#define DiagExInvalidkey_Nrc35()                              /* 0x35 */ UdsInterface_SendNegativeResponse(((UINT8)0x35)) 
#define DiagExceednumberOfAttempts_Nrc36()                    /* 0x36 */ UdsInterface_SendNegativeResponse(((UINT8)0x36)) 
#define DiagExRequiredTimeDelayNotExpired_Nrc37()             /* 0x37 */ UdsInterface_SendNegativeResponse(((UINT8)0x37)) 
#define DiagExTransferDataSuspended_Nrc71()                   /* 0x71 */ UdsInterface_SendNegativeResponse(((UINT8)0x71)) 
#define DiagExGeneralProgrammingFailure_Nrc72()               /* 0x72 */ UdsInterface_SendNegativeResponse(((UINT8)0x72)) 
#define DiagExWrongBlockSequenceCounter_Nrc73()               /* 0x73 */ UdsInterface_SendNegativeResponse(((UINT8)0x73)) 
#define DiagExRequestCorrectlyReceivedResponsePending_Nrc78() /* 0x78 */ UdsInterface_SendNegativeResponse(((UINT8)0x78)) 
#define DiagExSubFunctionNotSupportedInActiveSession_Nrc7E()  /* 0x7E */ UdsInterface_SendNegativeResponse(((UINT8)0x7E)) 
#define DiagExSerivcenotSupportInActiveSession_Nrc7F()        /* 0x7F */ UdsInterface_SendNegativeResponse(((UINT8)0x7F)) 
#define DiagExDefectWhileWriting_Nrc87()                      /* 0x87 */ UdsInterface_SendNegativeResponse(((UINT8)0x87)) 
#define DiagExSerivcenotSupport_voltageTooHigh_Nrc92()        /* 0x92 */ UdsInterface_SendNegativeResponse(((UINT8)0x92)) 
#define DiagExSerivcenotSupport_voltageTooLow_Nrc93()         /* 0x93 */ UdsInterface_SendNegativeResponse(((UINT8)0x93)) 


/*****************************************************************************
** Action Macro Definition
*****************************************************************************/


/*****************************************************************************
** Config Macro Definition
*****************************************************************************/


/*****************************************************************************
** Task Macro Definition
*****************************************************************************/


/*****************************************************************************
** Variables
*****************************************************************************/
extern Uds_DiagSts_E  g_uds_diag_status;
extern UINT8  g_u8_diag_neg_resp78_timer;
extern UINT16 g_u16_diag_resp78_timeout_timer;


/*****************************************************************************
** Constants
*****************************************************************************/


/*****************************************************************************
** Function prototypeseb
*****************************************************************************/
extern void UdsInterface_Init(void);

extern void UdsInterface_Handler10ms(void);

extern void UdsInterface_SendNegativeResponse(UINT8 response);

extern void UdsInterface_PutResponse( BOOL b_forbid_flag, UINT16 msg_length );

extern void UdsInterface_ReleaseRxBuff(void);

extern void UdsInterface_ClearResp78Flag(void);

extern void UdsAppl_DiagResetDiagTimer(void);

extern void UdsInterface_QuitWithoutSendNegativeResponse(void);



/*****************************************************************************
** other
*****************************************************************************/


/****************************************************************************/

#pragma CODE_SEG  DEFAULT


#endif	//_UDS_DIAG_INTERFACE_H_

/*****************************************************************************
** End File
*****************************************************************************/
